<?php
	header('Content-Type:text/html;charset=utf-8');
	session_start();	
	$userid = $_SESSION['userid'];		
	if($userid!=null&&$userid!=""){	
		require_once("db_manage.php");
		$title = $_POST['title'];
		$content = $_POST['content'];
		$type = $_POST['type'];
		$area = $_POST['area'];
		
		//insert into scence
		if(scene_add($title, $content, $type, $area, $userid)==1){		
			//get max scence id	
			$result = get_max_scene_id($userid);					
			while($rs=mysql_fetch_object($result)){					
				$cid = $rs->maxid;
			}			
			
			//upload dir
			$uploaddir = '../upload/images/';
			if ($_POST[sendfiles]) { 				
				foreach ($_FILES[photos][name] as $key => $value) {					
					//set image's name like 20081201211618 format
					$uploadfile = date('YmdHis');
					$path_parts = pathinfo( $value);
					//get image file's extension
					$ext = $path_parts["extension"];				
					//
					$uploadfile = $uploaddir . $uploadfile.$key .".". $ext ;
					$path_parts = pathinfo($uploadfile);
					$name = $path_parts["basename"];	
					//add to a full name
					if (move_uploaded_file($_FILES['photos']['tmp_name'][$key], $uploadfile)) { 					
						//echo "<br><br>name:".$name."<br>uploadfile:".$uploadfile."<br>cid:".$cid."<br>userid:".$userid;
						image_add($name, $uploadfile, $cid, "c", $userid);
					}
				}
			} 			
			$_SESSION['cid'] = $cid;
			echo "<script>location.href='admin_tour_over.php';</script>";
		}else{
			echo "<font color=red>insert scence wrong</font>";
		}		
	}
?>
